$("body").on('click', ".buy_classbtn", function() { //点击购买课程包
	var j = 0; //已购买
	if(j == 0) {
		if(j == 1) { //只有一个小孩
			orders("小明", 3);
		} else { //多个小孩 孩子选择
			var html = "";
			html += "<ul class='am-avg-sm-1 am-text-left font14'>";
			html += "<li>请选择要上课的孩子</li>";
			html += "<li>"
			for(var i = 0; i < 2; i++) {
				html += "<div class='childradio am-inline-block am-margin-top-xs' style='width:40%;margin-left:5%;'><input type=\"radio\" id=\"input" + i + "\" name=\"names\"/><label for=\"input" + i + "\" style='font-size:1.4rem;font-weight:600'>小明" + i + "</label></div>";
			}
			html += "</li>"
			html += "</ul>";
			$('#child_model .am-modal-hd').html("孩子选择");
			$("#child_model .am-modal-bd").html(html);
			$('#child_model').modal({
				relatedTarget: this,
				closeViaDimmer: false,
				onConfirm: function(options) {
					$("#child_model").removeData('amui.modal');
					orders("小明", 1);
				}
			});
		}
	} else {

		$("#alert_model .am-modal-bd").html("本课程已经购买！无需重复购买<span></span>");
		$('#alert_model').modal("open");
		clearFlag = self.setInterval("autoClose()", 1000); //每过一秒调用一次autoClose方法
	}
});

//购买课程包 几种状态
function orders(name, x) {
	var html = "";
	$('#class_model .am-modal-hd').html("购买课程包");
	switch(x) {
		case 0: //在课程关系链中没有前置关系的情况
			html += "<ul class='am-avg-sm-1 am-text-left font14'>";
			html += "<li>您已经有进行中的系统学习类课程，但与即将购买的课程不冲突，请在确认自身上课时间重组后再购买</li>";
			html += "<li>是否花费<span class='text-FF2A2A'>1800</span>(原价2000)个立方币购买本课程包?<li>"
			html += "</ul>";
			$("#class_model .am-modal-bd").html(html);
			$('#class_model').modal({
				relatedTarget: this,
				closeViaDimmer: false,
				onConfirm: function(options) {
					$("#class_model").removeData('amui.modal');
					console.log("在课程关系链中没有前置关系的情况,购买课程结束")
				}
			});
			break;
		case 1: //课程包关系链中有前置关系的情况
			html += "<ul class='am-avg-sm-1 am-text-left font14'>";
			html += "<li>您已经有进行中的系统学习类课程，购买当前课程包后，会在您上完本课程包的所有课程后自动为您排班上课</li>";
			html += "<li>是否花费<span class='text-FF2A2A'>1800</span>(原价2000)个立方币购买本课程包?<li>"
			html += "</ul>";
			$("#class_model .am-modal-bd").html(html);
			$('#class_model').modal({
				relatedTarget: this,
				closeViaDimmer: false,
				onConfirm: function(options) {
					$("#class_model").removeData('amui.modal');
					console.log("课程包关系链中有前置关系的情况,购买课程结束");
					resmodel(0); //购买成功 失败
				}
			});
			break;
		case 2: //正常购买
			html += "<ul class='am-avg-sm-1 am-text-left font14'>";
			html += "<li>是否花费<span class='text-FF2A2A'>1800</span>个立方币购买本课程包?<li>"
			html += "</ul>";
			$("#class_model .am-modal-bd").html(html);
			$('#class_model').modal({
				relatedTarget: this,
				closeViaDimmer: false,
				onConfirm: function(options) {
					$("#class_model").removeData('amui.modal');
					console.log("正常购买,购买课程结束")
				}
			});
			break;
		case 3: //有打折信息时的情况
			html += "<ul class='am-avg-sm-1 am-text-left font14'>";
			html += "<li>您当前距右参与优惠活动资格，是否花费<span class='text-FF2A2A'>1800</span>个立方币购买本课程包?<li>"
			html += "</ul>";
			$("#class_model .am-modal-bd").html(html);
			$('#class_model').modal({
				relatedTarget: this,
				closeViaDimmer: false,
				onConfirm: function(options) {
					$("#class_model").removeData('amui.modal');
					console.log("有打折信息时的情况,购买课程结束")
				}
			});
			break;
	}
}
//购买成功 购买失败
function resmodel(s) {
	if(s == 1) {
		$("#alert_model .am-modal-bd").html("购买成功！");
		count = 3;
		$('#alert_model').modal("open");
		clearFlag = self.setInterval("autoClose()", 1000); //每过一秒调用一次autoClose方法
	} else {
		$('#child_model .am-modal-hd').html("购买失败!");
		var html = "";
		html += "<ul class='am-avg-sm-1 am-text-center font14'>";
		/*html += "<li>购买失败！<li>"*/
		html += "<li>余额不足，是否立即?<li>"
		html += "</ul>";
		$("#child_model .am-modal-bd").html(html);
		$('#child_model').modal({
			relatedTarget: this,
			closeViaDimmer: false,
			onConfirm: function(options) {
				$("#child_model").removeData('amui.modal');
				location.href = "recharge.html"; //去充值页面
			}
		});
	}

}